package yi.Note;

import android.app.ActionBar;
import android.app.Activity;
import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent;
import android.drm.DrmStore;
import android.os.Bundle;
import android.view.*;
import android.widget.ImageButton;
import yi.Note.ui.EditorActivity;
import yi.Note.ui.NoteListFragment;

public class YiNoteActivity extends Activity
{
    private NoteListFragment mNoteList;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);
        setContentView(R.layout.main);
        FragmentManager fm = getFragmentManager();
        mNoteList = (NoteListFragment)fm.findFragmentById(R.id.note_list);
        mNoteList.getListView().setOnCreateContextMenuListener(this);

        //getActionBar().setDisplayOptions(ActionBar.DISPLAY_USE_LOGO|ActionBar.DISPLAY_SHOW_TITLE);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.main_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        return super.onContextItemSelected(item);
    }

    public static class NewActionProvider extends ActionProvider{
        /** An intent for launching the system settings. */
        private static final Intent mIntent = new Intent(EditorActivity.INTENT_NEW);

        /** Context for accessing resources. */
        private final Context mContext;
        /**
         * Creates a new instance.
         *
         * @param context Context for accessing resources.
         */
        public NewActionProvider(Context context) {
            super(context);
            mContext = context;
        }

        @Override
        public View onCreateActionView() {
            // Inflate the action view to be shown on the action bar.
            LayoutInflater layoutInflater = LayoutInflater.from(mContext);
            View view = layoutInflater.inflate(R.layout.action_bar_new, null);
            ImageButton button = (ImageButton) view.findViewById(R.id.button);
            // Attach a click listener for launching the system settings.
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mContext.startActivity(mIntent);
                }
            });
            return view;
        }

        @Override
        public boolean onPerformDefaultAction() {
            mContext.startActivity(mIntent);
            return true;
        }
    }
}
